var vm = new Vue({
	el: '#app',
	data: {
		items: [],
		loaded: false
	},
	mounted: function() {
		index();
		searchReleasedTaskList();
		serverGetReleaseTheRecordList();
	}
});
/**
 * 点击加载更多
 */
var scale = 10;

function loadMore() {
	for(var i = 0; i < 5; i++) {
		scale = scale + i;
	}
	searchReleasedTaskList();
	serverGetReleaseTheRecordList();
	serverGetReleaseTheAvailable();
}
/**
 * 查询是否认证
 */
function serverGetUserInfo() {
	$.ajax({
		type: "GET",
		url: ip + "platform/user/serverGetUserInfo.m",
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		success: function(data) {
			if(data.statusCode == 0) {
				var imgStatus = data.result.imgStatus;
				if(imgStatus == 1) {
					window.location.href = "extract.html";
				} else {
					$.toptip("未实名，请完成实名认证流程", 'error');
				}
			} else if(data.statusCode == 1000) {
				$.toptip("登录失效！", 'error');
				setTimeout('window.location.href = "signIn.html"', 1000);
			} else {
				$.toptip(data.resultDesc, 'error');
			}
		}
	});
}

function index() {
	$.ajax({
		type: "GET",
		url: ip + "trade/finance/serverGetUserAccountList.o",
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		success: function(data) {
			if(data.statusCode == 0) {
				vm.loaded = true;
				if(data.result[0].balanceAmount<0){
					$("#ky").text("0");
				}else{
					$("#ky").text(data.result[0].balanceAmount);
				}
				$("#ktq").text(data.result[0].unFreezeAmount);
				$("#dsf").text(data.result[0].freezeAmount);
			} else if(data.statusCode == 1000) {
				$.toptip("登录失效！", 'error');
				setTimeout('window.location.href = "signIn.html"', 1000);
			} else {
				$.toptip(data.resultDesc, 'error');
			}
		}
	});
}

function getHms() {
	var content = localStorage.getItem("content");
	var obj2 = JSON.parse(content);
	$("#ky").text(obj2.balanceAmount);
	$("#ktq").text(obj2.unFreezeAmount);
	$("#dsf").text(obj2.freezeAmount);
}
/**
 * 待释放
 */
function searchReleasedTaskList() {
	$("#tab1").text('');
	index();
	if(scale == null){
		scale = 10;
	}
	var searchReleasedTaskList = {
		rows: scale,
		page: 1
	};
	$.ajax({
		type: "GET",
		url: ip + "platform/transfer/searchReleasedTaskList.m",
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		data: searchReleasedTaskList,
		success: function(data) {
			if(data.statusCode == 0) {
				if(data.result == '') {
					$("#tab1").html('<div align="center">暂无记录</div>');
				}
				vm.loaded = true;
				var html = '';
				for(var i = 0; i < (data.result).length; i++) {
					$(".p10").css("display","block");
					html += '<ul class="accordion">' +
						'<li>' +
						'<div class="accordion-tit" onclick="addCurClass(this)">' +
						'<div class="weui-cell">' +
						'<div class="weui-cell__bd">' +
						timestampToTime(data.result[i].createTime) +
						'</div>' +
						'<div class="weui-cell__ft">' +
						data.result[i].totalReleased +
						'</div>' +
						'</div>' +
						'</div>' +
						'<div class="weui-cells f15">' +
						'<div class="weui-cell">' +
						'<div class="weui-cell__bd">' +
						'<p>待释放数量</p>' +
						'</div>' +
						'<div class="weui-cell__ft">' +
						data.result[i].hasReleased +
						'</div>' +
						'</div>' +
						'<div class="weui-cell">' +
						'<div class="weui-cell__bd">' +
						'<p>转入时间</p>' +
						'</div>' +
						'<div class="weui-cell__ft">' +
						timestampToTime(data.result[i].createTime) +
						'</div>' +
						'</div>' +
						'</div>' +
						'</li>' +
						'</ul>';
				}
				$("#tab1").append(html);
			} else {
				$.toptip(data.resultDesc, 'error');
			}
		}
	});
}
/**
 * 已释放
 */
function serverGetReleaseTheRecordList() {
	$("#tab2").text('');
	index();
	if(scale == null){
		scale = 10;
	}
	var serverGetReleaseTheRecordList = {
		rows: scale,
		page: 1
	};
	$.ajax({
		type: "GET",
		url: ip + "platform/admin/serverGetReleaseTheRecordList.m",
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		data: serverGetReleaseTheRecordList,
		success: function(data) {
			if(data.statusCode == 0) {
				if(data.result.result == '') {
					$("#tab2").html('<div align="center">暂无记录</div>');
				}
				vm.loaded = true;
				var html = '';
				for(var i = 0; i < (data.result.result).length; i++) {
					$(".p10").css("display","block");
					html += '<ul class="accordion">' +
						'<li>' +
						'<div class="accordion-tit" onclick="addCurClass(this)">' +
						'<div class="weui-cell">' +
						'<div class="weui-cell__bd">' +
						timestampToTime(data.result.result[i].paymentDate) +
						'</div>' +
						'<div class="weui-cell__ft">' +
						data.result.result[i].paymentAmount +
						'</div>' +
						'</div>' +
						'</div>' +
						'<div class="weui-cells f15">' +
						'<div class="weui-cell">' +
						'<div class="weui-cell__bd">' +
						'<p>描述</p>' +
						'</div>' +
						'<div class="weui-cell__ft">' +
						data.result.result[i].paymentRemark +
						'</div>' +
						'</div>' +
						'<div class="weui-cell">' +
						'<div class="weui-cell__bd">' +
						'<p>已释放数量</p>' +
						'</div>' +
						'<div class="weui-cell__ft">' +
						data.result.result[i].paymentAmount +
						'</div>' +
						'</div>' +
						'<div class="weui-cell">' +
						'<div class="weui-cell__bd">' +
						'<p>转入时间</p>' +
						'</div>' +
						'<div class="weui-cell__ft">' +
						timestampToTime(data.result.result[i].paymentDate) +
						'</div>' +
						'</div>' +
						'</div>' +
						'</li>' +
						'</ul>';
				}
				$("#tab2").append(html);
			} else {
				$.toptip(data.resultDesc, 'error');
			}
		}
	});
}
/**
 * 可用HMS
 */
function serverGetReleaseTheAvailable() {
	$("#tab3").text('');
	index();
	if(scale == null){
		scale = 10;
	}
	var serverGetReleaseTheRecordList = {
		rows: scale,
		page: 1
	};
	$.ajax({
		type: "GET",
		url: ip + "platform/userWallet/inWalletRecord.m",
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		data: serverGetReleaseTheRecordList,
		success: function(data) {
			if(data.statusCode == 0) {
				if(data.result.result == '') {
					$("#tab3").html('<div align="center">暂无记录</div>');
				}
				vm.loaded = true;
				var html = '';
				for(var i = 0; i < (data.result.result).length; i++) {
					if(data.result.result[i].status != 1){
						status = "确认中";
					}else{
						status = "成功";
					}
					$(".p10").css("display","block");
					html += '<ul class="accordion">' +
						'<li>' +
						'<div class="accordion-tit" onclick="addCurClass(this)">' +
						'<div class="weui-cell">' +
						'<div class="weui-cell__bd">' +
						timestampToTime(data.result.result[i].createTime) +
						'</div>' +
						'<div class="weui-cell__ft">' +
						data.result.result[i].mum +
						'</div>' +
						'</div>' +
						'</div>' +
						'<div class="weui-cells f15">' +
						'<div class="weui-cell">' +
						'<div class="weui-cell__bd">' +
						'<p>转入量</p>' +
						'</div>' +
						'<div class="weui-cell__ft">' +
						data.result.result[i].mum +
						'</div>' +
						'</div>' +
						'<div class="weui-cell">' +
						'<div class="weui-cell__bd">' +
						'<p>转入状态</p>' +
						'</div>' +
						'<div class="weui-cell__ft">' +
						status +
						'</div>' +
						'</div>' +
						'<div class="weui-cell">' +
						'<div class="weui-cell__bd">' +
						'<p>转入时间</p>' +
						'</div>' +
						'<div class="weui-cell__ft">' +
						timestampToTime(data.result.result[i].createTime) +
						'</div>' +
						'</div>' +
						'</div>' +
						'</li>' +
						'</ul>';
				}
				$("#tab3").append(html);
			} else {
				$.toptip(data.resultDesc, 'error');
			}
		}
	});
}

function addCurClass(tit) {
	$parent = $(tit).parent('li');
	if($parent.hasClass('cur')) {
		$parent.removeClass('cur');
		$parent.siblings().removeClass('cur');
	} else {
		$parent.addClass('cur');
		$parent.siblings().removeClass('cur');
	}
}